#ifndef  __MOTORSTASK_H_
#define  __MOTORSTASK_H_

#include "cmsis_os.h"
#include "BspM1_Driver.h"
#include "BspM2_Driver.h"
#include "BspM3_Driver.h"
#include <stdlib.h>

extern osMessageQueueId_t motorQueueHandle;
extern osMessageQueueId_t tcpQueueHandle;

#define HOMING_SPEED	1000000	//4 r/m

#define FAST_HOME_SPEED 10000000
#define SLOW_HOME_SPEED 1000000

#define BOARD_MOTOR_MAX  31
#define MOTOR_INDEX_TO_SDO_ADDR(channel)			(MOTOR_ADDR_BASE + channel)
#define SDO_ADDR_TO_MOTOR_INDEX(sdo_addr)			(sdo_addr - MOTOR_ADDR_BASE)
#define MOTOR_RPM_TO_DATA(rpm)								(895 * rpm)


#define M_STATUS_SPEED_ERR		0x00000800 /*电机莫名位置模式低速的错误*/
#define M_STATUS_SPI_error      0x00000400
#define M_STATUS_HOME_FINISH    0x00000200
#define M_STATUS_NEDDLE_CLASH   0x00000100
#define M_STATUS_LEFT_TRIG		0x00000080
#define M_STATUS_RIGHT_TRIG		0x00000040
#define M_STATUS_IN_POSITION	0x00000020
#define M_STATUS_IN_SPEED		0x00000010
#define M_STATUS_STOP			0x00000008
#define M_STATUS_STALL			0x00000004
#define M_STATUS_ERR			0x00000002
#define M_STATUS_HOMING			0x00000001

typedef enum{
	TYPE2_FAST_REACH = 0x21,
	TYPE2_FAST_LEAVE = 0x22,
	TYPE2_SLOW_REACH = 0x23,
	
	TYPE4_FAST_REACH = 0x41,
	TYPE4_FAST_LEAVE = 0x42,
	TYPE4_SLOW_REACH = 0x43,
}home_status_t;

typedef struct {
    uint8_t data[13];
    uint16_t length;
} Send_Data;

typedef struct {
    uint8_t data[128];
    uint16_t length;
} UDP_Send_Data;

typedef struct {
    uint8_t data[50];
    uint16_t length;
} Rev_Data;

void MotorsTask(void *pvParameters);


#endif
